﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace JH.Web.Framework.ActionFilters
{
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public class AccessControlAttributeFilter : FilterAttribute, IResultFilter, IActionFilter
    {
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {

        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
//Access-Control-Allow-Headers:Content-Type
//Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
//Access-Control-Allow-Origin:*
            filterContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Headers", "Content-Type");
            filterContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
            filterContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Origin", "http://localhost");
        }

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
        }
    }
}
